﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Xiaozilang_Ordering_System
{
    public partial class Pay : Form
    {
        public Pay()
        {
            InitializeComponent();
        }
        public static string[] odid = new string[50];
        public static string zfPassword;
        public static string ddColumn1OrderID, ddBSIDjudge;
        private void PayNow_Click(object sender, EventArgs e)
        {
            
            double usmoney =  Convert.ToDouble(Shopping_Cart.rr.Rows[0]["USMoney"].ToString());
            //int usmoney = int.Parse(denglu.Money);
            double pamoney = Convert.ToDouble(paymoney.Text);

            
            if (textBox1.Text != zfPassword)
            {
                MessageBox.Show("密码错误！！！");
            }
            else
            {
                if (usmoney >= pamoney)
                {
                    string sql = string.Format("update User1 set USMoney=USMoney-'{0}' where UStel='{1}'", pamoney, denglu.tel);
                    bool re = DBHelper.GetNonQuery(sql);
                    sql = string.Format("update Business set BSMoney=BSMoney+'{0}' where BSID='{1}'", pamoney, client.bsid);
                    re = DBHelper.GetNonQuery(sql);
                    for (int i = 0; i < odid.Length; i++)
                    {
                        if (odid [i]!=null)
                        {
                            sql = string.Format("update OrderDetail set number='0' ,orderStatus=0 where userID={0} and odID={1}", Shopping_Cart.UserJudge, odid[i]);
                            DBHelper.GetNonQuery(sql);
                            //下单的时间
                            if (ddColumn1OrderID!=null)
                            {
                                sql = string.Format("update Order1 set orderTime='{0}' where  userID= '{1}' and BSID={2} and OrderID={3}", DateTime.Now.ToString(), Shopping_Cart.UserJudge, ddBSIDjudge, ddColumn1OrderID);
                                DBHelper.GetNonQuery(sql);
                            }

                        }
                    }
                    MessageBox.Show("支付成功！");
                    Shopping_Cart.rechargeRefresh();
                    client cl = new client();
                    cl.Show();
                    this.Close();
                }
                else
                {
                    //MessageBox.Show("余额不足，请及时充值！", "余额不足");
                    DialogResult dr = MessageBox.Show("余额不足，请及时充值！", "余额不足!是否充值？:", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                    if (dr == DialogResult.OK)   //如果单击“是”按钮
                    {
                        AddMoney addMoney = new AddMoney();
                        addMoney.Show();
                        this.Close();
                    }
                    else if (dr == DialogResult.Cancel)
                    {
                        //不执行操作
                    }
                }
            }
        }

        private void PayLate_Click(object sender, EventArgs e)
        {
            client.SettlementAmount=0;
            //MessageBox.Show("订单将会保留十五分钟\n十五分钟后还未支付订单将会取消！", "提示");
            client cl = new client();
            cl.Show();
            this.Close();
        }

        private void Pay_Load(object sender, EventArgs e)
        {
            //文字背景透明
            label2.BackColor = Color.Transparent;
            label3.BackColor = Color.Transparent;
            label5.BackColor = Color.Transparent;
            Address.BackColor = Color.Transparent;
            paymoney.BackColor = Color.Transparent;

            string sql = string.Format("select * from User1 where UStel");
            Shopping_Cart.rechargeRefresh();
            Address.Text = denglu.address;
            paymoney.Text = client.SettlementAmount.ToString();
            client.SettlementAmount = 0;
        }

        private void paymoney_Click(object sender, EventArgs e)
        {

        }
    }
}
